home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / XMSLI202.ZIP / XMSDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-03-17  |  6KB  |  178 lines

  1. Program XMSLibDemo;
  2. { Copyright (c) 1994 by Andrew Eigus              Fido Net: 2:5100/20.12 }
  3. { XMS Interface V2.02 for Turbo Pascal version 7.0 demonstration program }
  4.  
  5. (*
  6.   Tested on IBM 486 SX 33Mhz with 4MB RAM with the following configuration:
  7.      1)  HIMEM.SYS  (MS-DOS 6.2 XMS memory manager)
  8.      2)  HIMEM.SYS  (MS-DOS 6.2 XMS memory manager)
  9.      EMM386.EXE (MS-DOS 6.2 EMS memory manager)
  10.  
  11.   If any inpredictable errors occur in your system while running this demo,
  12.   please be so kind to inform me:
  13.  
  14.     AndRew's BBS Phone: 003-712-559777 (Riga, Latvia) 24h 2400bps
  15.     Voice Phone:        003-712-553218
  16.     Fido Net:        2:5100/20.12
  17. *)
  18.  
  19. {X+}{$R-}
  20.  
  21. uses XMSLib;
  22.  
  23. type
  24.   TMsg = array[1..14] of Char;
  25.  
  26.   TUMBAllocRec = record
  27.     Size : word;
  28.     SegAddr : word
  29.   end;
  30.  
  31. const
  32.   Message1 : TMsg = 'First message ';
  33.   Message2 : TMsg = 'Second message';
  34.  
  35.   YesNo : array[boolean] of string[3] = ('No', 'Yes');
  36.   A20State : array[boolean] of string[8] = ('Disabled', 'Enabled');
  37.  
  38. var
  39.   Version, Memory, Handle, BlockLength : word;
  40.   Locks, FreeHandles : byte;
  41.   HMAAvailable : boolean;
  42.   Address : pointer;
  43.   UMB : longint;
  44.  
  45. Function Hex(Num : longint; Places : byte) : string;
  46. const HexTab : array[0..15] of Char = '0123456789ABCDEF';
  47. var
  48.   HS : string[8];
  49.   Digit : byte;
  50. Begin
  51.   HS[0] := Chr(Places);
  52.   for Digit := Places downto 1 do
  53.   begin
  54.     HS[Digit] := HexTab[Num and $0000000F];
  55.     Num := Num shr 4
  56.   end;
  57.   Hex := HS
  58. End; { Hex }
  59.  
  60. Function Check(Result : byte; Func : string) : byte;
  61. Begin
  62.   if Result <> xmsrOk then
  63.     WriteLn(Func, ' returned ',
  64.       Hex(Result, 2), 'h (', Result, '): ', XMS_GetErrorMsg(Result));
  65.   Check := Result
  66. End; { Check }
  67.  
  68. Procedure ShowA20State;
  69. var State : boolean;
  70. Begin
  71.   State := XMS_QueryA20;
  72.   if Check(XMSResult, 'XMS_QueryA20') = xmsrOk then
  73.     WriteLn('A20 state: ', A20State[State])
  74. End; { ShowA20State }
  75.  
  76. Procedure Wait4Return;
  77. Begin
  78.   WriteLn;
  79.   WriteLn('Press ENTER to continue');
  80.   ReadLn
  81. end; { Wait4Return }
  82.  
  83.  
  84. Begin
  85.   WriteLn('XMS Library V2.02 Demonstration program by Andrew Eigus'#10);
  86.   if XMS_Setup then
  87.   begin
  88.  
  89.     Version := XMS_GetVersion(XMS);
  90.     if Check(XMSResult, 'XMS_GetVersion(XMS)') = xmsrOk then
  91.       WriteLn('XMS version ', Hi(Version), '.', Lo(Version), ' present');
  92.     Version := XMS_GetVersion(XMM);
  93.     if Check(XMSResult, 'XMS_GetVersion(XMM)') = xmsrOk then
  94.       WriteLn('XMM version ', Hi(Version), '.', Lo(Version), ' detected');
  95.     HMAAvailable := XMS_HMAAvail;
  96.     if Check(XMSResult, 'XMS_HMAAvail') = xmsrOk then
  97.       WriteLn('HMA Available: ', YesNo[HMAAvailable]);
  98.  
  99.     WriteLn;
  100.     Memory := XMS_MemAvail;
  101.     if Check(XMSResult, 'XMS_MemAvail') = xmsrOk then
  102.       WriteLn('Free XMS memory available: ', Memory, ' KB')
  103.     else
  104.       if XMSResult = xmsrNoMoreMem then Halt(xmsrNoMoreMem);
  105.     Memory := XMS_MaxAvail;
  106.     if Check(XMSResult, 'XMS_MaxAvail') = xmsrOk then
  107.       WriteLn('Largest XMS memory block: ', Memory, ' KB');
  108.  
  109.     WriteLn;
  110.     if HMAAvailable then
  111.       if Check(XMS_AllocHMA($FFFF), 'XMS_AllocHMA') = xmsrOk then
  112.       begin
  113.         WriteLn('HMA: Block allocated');
  114.         if Check(XMS_FreeHMA, 'XMS_FreeHMA') = xmsrOk then
  115.           WriteLn('HMA: Block released')
  116.       end;
  117.  
  118.     Wait4Return;
  119.  
  120.     WriteLn('XMS data transfer test'#10);
  121.     WriteLn('Message1: ', Message1);
  122.     WriteLn('Message2: ', Message2);
  123.  
  124.     Handle := XMS_AllocEMB(1);
  125.     if Check(XMSResult, 'XMS_AllocEMB') = xmsrOk then
  126.     begin
  127.       WriteLn('1 KB EMB allocated. Handle number: ', Hex(Handle, 4), 'h');
  128.       { Now copy our little Message1 to extended memory }
  129.       if Check(XMS_MoveToEMB(Handle, Message1, SizeOf(TMsg)),
  130.         'XMS_MoveToEMB') = xmsrOk then WriteLn('Transfer to XMS: OK');
  131.       { Now copy it back to the second string }
  132.       if Check(XMS_MoveFromEMB(Handle, Message2, SizeOf(TMsg)),
  133.         'XMS_MoveFromEMB') = xmsrOk then WriteLn('Transfer from XMS: OK');
  134.       WriteLn('Message1: ', Message1);
  135.       WriteLn('Message2: ', Message2);
  136.       WriteLn;
  137.       if Check(XMS_ReallocEMB(Handle, 2),
  138.         'XMS_ReallocEMB') = xmsrOk then
  139.         WriteLn('EMB reallocated. New size: 2 KB');
  140.       WriteLn;
  141.       Address := XMS_LockEMB(Handle);
  142.       if Check(XMSResult, 'XMS_LockEMB') = xmsrOk then
  143.         WriteLn('EMB locked at linear memory address ',
  144.           Hex(Longint(Address), 8), 'h');
  145.  
  146.       WriteLn;
  147.       FreeHandles := XMS_EMBHandlesAvail(Handle);
  148.       if Check(XMSResult, 'XMS_EMBHandlesAvail') = xmsrOk then
  149.         WriteLn('EMB Handles available: ', FreeHandles);
  150.       Locks := XMS_EMBLockCount(Handle);
  151.       if Check(XMSResult, 'XMS_EMBLockCount') = xmsrOk then
  152.         WriteLn('EMB Lock count: ', Locks);
  153.       BlockLength := XMS_EMBSize(Handle);
  154.       if Check(XMSResult, 'XMS_EMBSize') = xmsrOk then
  155.         WriteLn('EMB Length: ', BlockLength, ' KB');
  156.  
  157.       WriteLn;
  158.       if Check(XMS_UnlockEMB(Handle), 'XMS_UnlockEMB') = xmsrOk then
  159.           WriteLn('EMB unlocked');
  160.  
  161.       WriteLn;
  162.       if Check(XMS_FreeEMB(Handle), 'XMS_FreeEMB') = xmsrOk then
  163.         WriteLn('EMB released');
  164.  
  165.       Wait4Return
  166.     end;
  167.  
  168.     UMB := XMS_AllocUMB($FFFF);
  169.     if Check(XMSResult, 'XMS_AllocUMB') = xmsrOk then
  170.     begin
  171.       WriteLn('UMB allocated at segment base ',
  172.         Hex(TUMBAllocRec(UMB).SegAddr, 4), 'h');
  173.       WriteLn('Actual size: ', TUMBAllocRec(UMB).Size, ' paragraphs'#10);
  174.       if Check(XMS_FreeUMB(TUMBAllocRec(UMB).SegAddr),
  175.         'XMS_FreeUMB') = xmsrOk then WriteLn('UMB released')
  176.     end;
  177.   end else WriteLn('XMS not present.')
  178. End.